package com.itheima.customer;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ConsumerConfig {

    public static final String EXCHANGE_RAABIT="informationService";
    public static final String QUEUE_SMS="shortMessage_route";
    public static final String QUEUE_EMAIL="emailMessage_route";
    public static final String ROUTE_SMS="sms";
    public static final String ROUTE_EMAIL="email";

//    声明交换机
    @Bean("informationService")
    public Exchange getExchange(){
        return ExchangeBuilder.directExchange(EXCHANGE_RAABIT).durable(true).build();
    }

//    声明队列
    @Bean("shortMessage")
    public Queue getSMSQueue(){
        return new Queue(QUEUE_SMS);
    }

    @Bean("emailMessage")
    public Queue getEmailQueue(){
        return new Queue(QUEUE_EMAIL);
    }
//    绑定交换机和队列
    @Bean("SMSBinding")
    public Binding getSMSBinding(@Qualifier("informationService") Exchange exchange,@Qualifier("shortMessage") Queue queue){
       return BindingBuilder.bind(queue).to(exchange).with(ROUTE_SMS).noargs();
    }
    @Bean("EmailBinding")
    public Binding getEamilBinding(@Qualifier("informationService") Exchange exchange,@Qualifier("emailMessage") Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTE_EMAIL).noargs();
    }

}
